package com.tgy.leetcode;


import java.util.Stack;

class MyQueue {

    private Stack<Integer> leftStack;
    private Stack<Integer> rightStack;

    /** Initialize your data structure here. */
    public MyQueue() {

        leftStack = new Stack<>();
        rightStack = new Stack<>();
    }

    /** Push element x to the back of queue. */
    public void push(int x) {

        leftStack.push(x);
    }

    /** Removes the element from in front of queue and returns that element. */
    public int pop() {

        leftAddToRight();
        return rightStack.pop();
    }

    /** Get the front element. */
    public int peek() {

        leftAddToRight();
        return rightStack.peek();
    }
    /** Returns whether the queue is empty. */
    public boolean empty() {

        return leftStack.isEmpty() && rightStack.isEmpty();
    }

    private void leftAddToRight() {

        checkEmpty();

        if (rightStack.isEmpty()) {

            while (!leftStack.isEmpty()) {

                rightStack.push(leftStack.pop());
            }
        }
    }

    private void checkEmpty() {

        if (empty()) {
            throw new  RuntimeException("队列为空");
        }
    }
}

public class _232_用栈实现队列 {

    public static void main(String[] args) {



    }
}
